<?php
/**
 * https://gitee.com/litephp
 * http://www.dazhetu.cn/
 * jay_fun 410136330@qq.com
 * Date: 2019/1/10
 * Time: 16:44
 */

namespace app\admin\controller\content;

use app\common\controller\BaseAdmin;
use app\common\model\content\Pbank as PbankModel;
use app\common\model\content\Music as MusicModel;

/**
 * @title 平台银行卡
 * Class AdvCategory
 * @package app\admin\controller\content
 */
class Pbank extends BaseAdmin
{
    /**
     * @title 列表页
     * @return mixed
     */
    public function index()
    {
        $db = PbankModel::order('id','desc');


        return $this->_list($db);
    }

    /**
     * @title 添加操作
     * @return array|mixed
     */
    public function add()
    {
        return $this->_form(new PbankModel(), 'form');
    }

	protected function _add_form_before(&$data){
        if ($this->request->isPost()){
            $data['create_time'] = $this->request->time();
        }
    }

    /**
     * @title 编辑操作
     * @return array|mixed
     */
    public function edit()
    {
        return $this->_form(new PbankModel(), 'form');
    }
   /* protected function _form_after(&$data)
    {
        if ($this->request->isGet()){

        }else{
            $savePath = env('root_path').DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'qrcode/';
            $webPath = '/qrcode/';
            $qrData = 'http://voice.lookupok.com/api/index/index?id='.$data['id'];
            $qrLevel = 'H';
            $qrSize = '8';
            $savePrefix = 'NickBai';
            if($filename = createQRcode($savePath, $qrData, $qrLevel, $qrSize, $savePrefix)){
                $pic = $webPath . $filename;
                $this->_change(new AdvsCategoryModel(), $data['id'] ,['qrcode' => $pic]);
            }
        }
    }*/

    /**
     * @title 禁用/启用
     */
    public function change()
    {
        $id = $this->request->post('id');
        $state = $this->request->post('state');
        $this->_change(new AdvsCategoryModel(), $id, ['state' => $state]);
    }

    /**
     * @title 删除操作
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function del()
    {
        $ids = $this->request->post('ids');
        
        $this->_del(new PbankModel(), $ids);
    }
}